package com.common.util.repay_plan;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;

/**
 * @describe:获取还款计划的工具类
 */
public class RepayPlanUtil {

    /**
     * 获取还款计划
     * @param repayPlanCondition 还款计划需要的计算性参数
     * @return 还款计划
     */
    public static ArrayList<RepayPlan> getPlan(RepayPlanCondition repayPlanCondition) {
        switch (repayPlanCondition.getType()) {
            case WAY1:     //等额本金
                return AverageCapital.getPlan(repayPlanCondition);
            case WAY2:    //按月付息到期还本
                return DueToPayInterestOnSchedule.getPlan(repayPlanCondition, RepayDateUtil.PeriodsUnit.MONTH);
            case WAY3:    //按季节付息到期还本
                return DueToPayInterestOnSchedule.getPlan(repayPlanCondition, RepayDateUtil.PeriodsUnit.SEASON);
            case WAY4:     //到期还本付息
                return DebtServiceDue.getPlan(repayPlanCondition);
            case WAY5:      //等本等息
                return EqualPrincipalAndInterest.getPlan(repayPlanCondition);
            default:
                return null;
        }
    }


    /**
     * 测试获取还款计划算法
     * @param args
     */
    public static void main(String[] args) {
        ArrayList<RepayPlan> repayPlanList = getPlan(RepayPlanCondition
                .createCondition()
                .setType(RepayPlanCondition.Type.WAY5)
                .setFixedRepayDay(20)
                .setAmt(new BigDecimal(10000))
                .setAnnualNumberOfDays(360)
                .setLoanDays(90)
                .setRate(new BigDecimal(0.12))
                .setStartTime(new Date()));
        for (RepayPlan repayPlan : repayPlanList) {
            System.out.println(repayPlan.toString());
        }
    }


}
